package collecttion.demo0809;

import homework.day08.Point;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo2 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(5,6));
        list.add(new Point(13,87));
        list.add(new Point(55,35));
        list.add(new Point(9,4));
        list.add(new Point(2,1));
        list.add(new Point(99,88));

        //Collections.sort(list);  //编译错误
//        Comparator<Point> c = new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int olen1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
//                int olen2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
//                //return olen1-olen2; //升序  反过来减可看做从大到小排
//                return olen2-olen1; //降序
//            }
//        };
//        Collections.sort(list,c);


        Collections.sort(list,(o1, o2)->
                        o1.getX()*o1.getX()+o1.getY()*o1.getY() -
                        o2.getX()*o2.getX()-o2.getY()*o2.getY()
                );
        System.out.println(list);
    }
}
